import 'package:abc/view/GradientButton.dart';
import 'package:flutter/material.dart';

// 定义按钮回调的类型别名
typedef ButtonCallback = void Function()?;

class UpLevelUnlockSheet extends StatelessWidget {
  // --- 数据参数 ---
  final int currentLevel; //当前等级
  final int toLevel; // 需要升到的等级

  // --- 回调参数 ---

  final ButtonCallback? onGoRecharge;

  const UpLevelUnlockSheet({
    Key? key,
    required this.currentLevel,
    required this.toLevel,
    this.onGoRecharge,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
      child: Padding(
        padding: MediaQuery.of(context).viewInsets, // 解决键盘遮挡问题
        child: Column(
          mainAxisSize: MainAxisSize.min,
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: <Widget>[
            // --- 顶部标题和关闭按钮 ---
            _buildHeader(context),
            const SizedBox(height: 20),
            // --- 中间内容区 ---
            Padding(
              padding: const EdgeInsets.symmetric(horizontal: 16.0),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  RichText(
                    text: TextSpan(
                      // 基础样式（对应原 TextStyle，作用于未单独设置的文本）
                      style: TextStyle(
                        fontSize: 15,
                        color: Color(0xFF3A3A3A),
                        fontWeight: FontWeight.w400,
                        height: 1,
                      ),
                      children: [
                        TextSpan(text: '当前章节用户等级达到 '),
                        TextSpan(
                          text: 'Lv${toLevel}',
                          style: TextStyle(color: Color(0xFFF85046)),
                        ),
                        TextSpan(text: ' 即可观看'),
                      ],
                    ),
                  ),
                  const SizedBox(height: 66),
                  // 升级
                  Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      _buildLevelTag(currentLevel, '当前'),
                      const SizedBox(width: 38),
                      Image.asset(
                        'assets/images/ic_up_level.png',
                        width: 48,
                        height: 48,
                      ),
                      const SizedBox(width: 38),
                      _buildLevelTag(toLevel, '升级为'),
                    ],
                  ),
                  const SizedBox(height: 52),

                  // 充值升级按钮
                  GradientButton(
                    text: '充值升级',
                    margin: EdgeInsetsGeometry.all(0),
                    gradientColors: [Color(0xFFFFDB83), Color(0xFFFFA335)],
                    onPressed: onGoRecharge,
                  ),
                ],
              ),
            ),
            const SizedBox(height: 41),
          ],
        ),
      ),
    );
  }

  // 顶部标题和关闭按钮
  Widget _buildHeader(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.fromLTRB(0, 16, 16, 0),
      child: Stack(
        alignment: Alignment.center,
        children: [
          const Positioned(
            child: Padding(
              padding: EdgeInsetsGeometry.only(top: 8),
              child: Text(
                '提示',
                style: TextStyle(
                  fontSize: 16,
                  fontWeight: FontWeight.bold,
                  color: Colors.black,
                  height: 1,
                ),
              ),
            ),
          ),

          Row(
            mainAxisAlignment: MainAxisAlignment.end,
            children: [
              InkWell(
                child: Image.asset(
                  'assets/images/ic_close.png',
                  width: 18,
                  height: 18,
                ),
                onTap: () => Navigator.of(context).pop(),
              ),
            ],
          ),
        ],
      ),
    );
  }

  // 等级样式
  Widget _buildLevelTag(int level, String status) {
    return Column(
      children: [
        Text(
          'Lv${level}',
          style: TextStyle(
            fontSize: 15,
            fontWeight: FontWeight.w600,
            color: Color(0xFF3A3A3A),
            height: 1.3,
          ),
        ),
        Text(
          status,
          style: TextStyle(
            fontSize: 15,
            fontWeight: FontWeight.w400,
            color: Color(0xFF999999),
            height: 1.3,
          ),
        ),
      ],
    );
  }
}
